package com.wdemo.config;

import jakarta.annotation.PostConstruct;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.concurrent.atomic.AtomicReference;

/**
 * @ClassName AIProperties
 * @Description Ai提示词配置
 * @Author WDEMO
 * @Date 2025/8/29 12:47
 */
@Component
@Slf4j
@Getter
public class AIProperties {

    /**
     * 默认系统提示词
     */
    @Value("classpath:system-chat-message.txt")
    private Resource resourceSystem;


    /**
     * 默认系统提示词
     */
    @Value("classpath:system-role-game.txt")
    private Resource resourceGame;
    /**
     * 客服系统提示词
     */
    @Value("classpath:service-chat-message.txt")
    private Resource resourceService;

    /**
     * Pdf提示词
     */
    @Value("classpath:pdf-chat-message.txt")
    private Resource resourcePdf;

    private final AtomicReference<String> systemChatMessage= new AtomicReference<>();

    private final AtomicReference<String> systemGameMessage= new AtomicReference<>();

    private final AtomicReference<String> systemServiceMessage= new AtomicReference<>();

    private final AtomicReference<String> systemPdfMessage= new AtomicReference<>();

    @PostConstruct
    private void init(){
        try {
            String systemChatText = new String(resourceSystem.getInputStream().readAllBytes());
            String systemGameText = new String(resourceGame.getInputStream().readAllBytes());
            String systemServiceText = new String(resourceService.getInputStream().readAllBytes());
            String systemPdfText = new String(resourcePdf.getInputStream().readAllBytes());
            systemChatMessage.set(systemChatText);
            systemGameMessage.set(systemGameText);
            systemServiceMessage.set(systemServiceText);
            systemPdfMessage.set(systemPdfText);
            log.info("系统提示词初始化完成");
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

}
